package controle;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

import servicos.FalhaDeInclusaoException;

import dominio.Login;

@ManagedBean(name = "LoginMB")
public class LoginManagedBean {
	private Login login = new Login();

	public Login getLogin() {
		return login;
	}

	public void setLogin(Login login) {
		this.login = login;
	}

	public String fazerLogin() {
		String end = null;
		try {
			end = "/index";
			if (login.verificaLogin()) {

				end = "/faces/paginas/principal.xhtml";
			} else {
				FacesContext contexto = FacesContext.getCurrentInstance();
				contexto.addMessage(null, new FacesMessage(
						FacesMessage.SEVERITY_ERROR,
						"Login e Senha invalido !", "Digite Novamente"));

				end = null;
			}

		} catch (FalhaDeInclusaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return end;
	}

}
